package com.freecloud.javabasics.thread.state;

import java.util.concurrent.TimeUnit;

/**
 * 线程复位
 * @Author: maomao
 * @Date: 2020-01-21 17:01
 */
public class ThreadResetDemo {


    public static void main(String[] args) throws InterruptedException {

        Thread thread = new Thread(()->{
            while (true){
                if(Thread.currentThread().isInterrupted()){
                    System.out.println("before :  " + Thread.currentThread().isInterrupted());
                    Thread.interrupted();//复位-回到初始状态
                    System.out.println("after :  " + Thread.currentThread().isInterrupted());
                }
            }
        });
        thread.start();

        TimeUnit.SECONDS.sleep(1);

        thread.interrupt();
    }
}
